package ru.ifmo.contest.games3;

/**
 * Фак мой мозг. Что я делаю. Сон,прийди ко мне
 * @author avhaliullin
 */

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class TaskE {
    FastScanner in;
    PrintWriter out;

    private void readMatrix(int[][] m) {
        for (int i = 0; i < m.length; i++) {
            for (int j = 0; j < m[0].length; j++) {
                m[i][j] = in.nextInt();
            }
        }
    }


    private static boolean checkStrong(int[][] a, int[][] b, int n, int m, int x, int y) {
        for (int i = 0; i < n; i++)
            if (b[x][i] > b[x][y])
                return false;
        for (int i = 0; i < m; i++)
            if (a[i][y] > a[x][y])
                return false;
        return true;
    }

    public void solve() throws IOException {
        int m = in.nextInt();
        int n = in.nextInt();
        int[][] a = new int[m][n];
        int[][] b = new int[m][n];
        readMatrix(a);
        readMatrix(b);
        List<Pair> result = new ArrayList<Pair>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (checkStrong(a, b, n, m, i, j)) {
                    result.add(new Pair(i, j));
                }
            }
        }
        out.println(result.size());
        for (Pair pair : result) {
            out.println((pair.a + 1) + " " + (pair.b + 1));
        }
    }

    public void run(String fileName) {
        try {
            in = new FastScanner(new File(fileName + ".in"));
            out = new PrintWriter(new File(fileName + ".out"));

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] arg) {
        new TaskE().run("nash");
    }

    class Pair {
        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int a;
        public int b;
    }
}
